package com.qf.lanzhou.blog.api.util;

import org.apache.commons.dbutils.BasicRowProcessor;
import org.apache.commons.dbutils.GenerousBeanProcessor;
import org.apache.commons.dbutils.RowProcessor;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

/**
 * @author jack
 * 驼峰映射
 */

//用法参考        BeanHandler beanHandler = BeanProcessor.getBeanHandler(Goods.class);
//        BeanListHandler<Object> beanListHandler = BeanProcessor.getBeanListHandler(Goods.class);

public class BeanProcessor {
    private static GenerousBeanProcessor bean;
    private static RowProcessor processor;
    private static BeanHandler<Object> beanHandler;
    private static BeanListHandler<Object> beanListHandler;



    public static BeanHandler getBeanHandler(Class clazz) {
        bean = new GenerousBeanProcessor();
        processor = new BasicRowProcessor(bean);
        beanHandler = new BeanHandler(clazz, processor);
        return beanHandler;
    }


    public static BeanListHandler getBeanListHandler(Class clazz) {
        bean = new GenerousBeanProcessor();
        processor = new BasicRowProcessor(bean);
        beanListHandler = new BeanListHandler(clazz,processor);
        return beanListHandler;
    }
}